package com.wuyou.dataStructure.tree;

import java.util.ArrayList;
import java.util.List;

/**
 * 后续遍历
 * 左-右-根
 */
public class PostorderTraversal {


    public List<Integer> sol_1(TreeNode root) {
        List<Integer> ans = new ArrayList<>();
        preOrder(root, ans);
        return ans;
    }

    public void preOrder(TreeNode root, List<Integer> ans) {
        if (root == null) {
            return;
        }
        preOrder(root.left, ans);
        preOrder(root.right, ans);
        ans.add(root.val);
    }
}
